package com.webvihar.access2db.asynctasks;

import android.content.Context; 
import android.os.AsyncTask;

import com.webvihar.access2db.restapi.A2DbWebResult;
import com.webvihar.access2db.restapi.AbstractA2DbWebRequest;
import com.webvihar.access2db.utils.NetworkConnection;
import com.webvihar.common.utils.Logger;

/**
 * AbstractAsyncTask.java
 * 
 * @author Viswanath Kumar Sandu
 */

public abstract class AbstractAsyncTask extends AsyncTask<AbstractA2DbWebRequest, Void, A2DbWebResult<?>> {

	protected Context context;
	protected boolean isConnected;
	protected boolean shouldToastWhenNoNetworkIsPresent;

	/**
	 * If context isn't available, pass null. Note that for this case, the
	 * system will not be able to detect whether or not a network connection
	 * exists.
	 */
	protected AbstractAsyncTask(Context context, boolean shouldToastWhenNoNetworkIsPresent) {
		if (context != null) this.context = context.getApplicationContext();
		this.shouldToastWhenNoNetworkIsPresent = shouldToastWhenNoNetworkIsPresent;
	}

	@Override
	protected void onPreExecute() {
		super.onPreExecute();
		if (context != null) {
			isConnected = NetworkConnection.isConnected(context);
			Logger.logInfo(this.getClass().getName(), String.format("isConnected to network = %s", String.valueOf(isConnected)));
		}
	}

	@Override
	protected A2DbWebResult<?> doInBackground(AbstractA2DbWebRequest... params) {
		return null;
	}

	@Override
	protected void onPostExecute(A2DbWebResult<?> result) {
		super.onPostExecute(result);
	}
}
